

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var color_sensor = "#FF0000";




    //红外接收模块
    Blockly.Blocks.microbit_irInit = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_IR)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P14', "pin14"],
            ['P15', "pin15"],
             ]),"irPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //红外接收模块
    Blockly.Blocks.microbit_irLogic = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_IRLOGICVALUE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
    this.setTooltip('');
        }
    };

    //红外接收模块
    Blockly.Blocks.microbit_ir = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_IRRECEIVERDATA)
            .appendField(new Blockly.FieldDropdown([
            ['A', "0x45"],
            ['B', "0x46"],
            ['C', "0x47"],
            ['D', "0x44"],
            ['UP', "0x40"],
            ['+', "0x43"],
            ['LEFT', "0x07"],
            ['OK', "0x15"],
            ['RIGHT', "0x09"],
            ['0', "0x16"],
            ['DOWN', "0x19"],
            ['-', "0x0D"],
            ['1', "0x0C"],
            ['2', "0x18"],
            ['3', "0x5E"],
            ['4', "0x08"],
            ['5', "0x1C"],
            ['6', "0x5A"],
            ['7', "0x42"],
            ['8', "0x52"],
            ['9', "0x4A"],
        ]),"mappingValue")
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    return Blockly;
}

module.exports = SensorbitUnoBlocks;

